package com.supermap.dataservice.common;

import com.supermap.dataservice.common.dao.SuggestionDao;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.common.SuggestionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dubbo.config.annotation.Service;

import javax.annotation.Resource;

/**
 * @Author:langhongshuai
 * @Description:意见业务逻辑层
 * @Date:18/3/12 上午11:45
 */
@Service
public class SuggestionServiceImpl implements SuggestionService {

    /**
     *使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(SuggestionServiceImpl.class);

    @Resource
    private SuggestionDao suggestionDao;

    @Override
    public JSONUtil saveSuggestion(String comment,String userId) {
        //初始化Json封装工具类
        JSONUtil jsonUtil = new JSONUtil();
        try {
            //保存反馈的意见
            suggestionDao.saveSuggestion(comment,userId);

            //保存反馈的意见后返回的json数据
            jsonUtil.setMsg("Save suggestion success！");
            jsonUtil.setIsSuccess(true);
            jsonUtil.setCode(200);
            jsonUtil.setData(comment);
        }catch (Exception e) {
            //捕捉数据库异常
            logger.error("SuggestionServiceImpl=>saveSuggestion=>DaoException:"+e.getMessage());
            jsonUtil.setMsg("Save suggestion flase！");
            jsonUtil.setIsSuccess(false);
            jsonUtil.setCode(100);
        }
        return jsonUtil;
    }
}
